import Vue from 'vue'
import VueRouter from 'vue-router'

// 懒加载
// import Home from '../views/home/Home.vue'
const Home = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../views/home/Home.vue')
// import Login from '../views/login/Login.vue'
const Login= () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../views/login/Login.vue')
// import Welcome from '../views/welcome/Welcome.vue'
const Welcome = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../views/welcome/Welcome.vue')

// import Users from '../views/users/Users.vue'
const Users = () => import(/* webpackChunkName: "User_Rights_Roles" */ '../views/users/Users.vue')
// import Rights from '../views/power/Rights.vue'
const Rights = () => import(/* webpackChunkName: "User_Rights_Roles" */ '../views/power/Rights.vue')
// import Roles from '../views/power/roles.vue'
const Roles = () => import(/* webpackChunkName: "User_Rights_Roles" */ '../views/power/Roles.vue')



// import Cate from '../views/goods/Cate.vue'
const Cate = () => import(/* webpackChunkName: "Cate_Params" */ '../views/goods/Cate.vue')
// import Params from '../views/goods/Params.vue'
const Params = () => import(/* webpackChunkName: "Cate_Params" */ '../views/goods/Params.vue')

// import GoodsList from '../views/goods/List.vue'
const GoodsList = () => import(/* webpackChunkName: "GoodsList_Add */ '../views/goods/List.vue')
// import Add from '../views/goods/Add.vue'
const Add = () => import(/* webpackChunkName: "GoodsList_Add" */ '../views/goods/Add.vue')


// import Order from '../views/order/Order.vue'
const Order = () => import(/* webpackChunkName: "Order_Report" */ '../views/order/Order.vue')
// import Report from '../views/report/Report.vue'
const Report = () => import(/* webpackChunkName: "Order_Report" */ '../views/report/Report.vue')

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect: '/home' 
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home
  },
  {
    path: '/home',
    component: Home,
    children:[
      {path: '/welcome',component: Welcome},
      {path: '/users',component: Users}, 
      {path:'/roles',component: Roles},
      {path: '/categories',component: Cate},
      {path: '/params',component: Params}, 
      {path: '/goods',component: GoodsList}, 
      {path: '/add',component: Add}, 
      {path: '/orders',component: Order }, 
      {path: '/reports',component: Report}, 
      {path:'/rights',component:Rights}

    ]
  },
  // {path: '/welcome',component: Welcome},
  // {path: '/users',component: Users},
  // {path:'/roles',component: Roles},
  // {path: '/categories',component: Cate}, 
  // {path: '/params',component: Params},
  // {path: '/goods',component: GoodsList}, 
  // {path: '/add',component: Add}, 
  // {path: '/order',component: Order }, 
  // {path: '/reports ',component: Report},
  // {path:'/rights',component:Rights}

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 挂载路由导航守卫
router.beforeEach((to,from,next) =>{

  if(to.path === '/login')return next()
//   //获取token
  const tokenStr = window.sessionStorage.getItem('token')
  if(!tokenStr) return next('/login')
  next()
})


export default router
